<?php
/**
 * 申请破产救济金
 * ApplyBrokeAlms.php 
 */
class ApplyBrokeAlms extends APIBase {
	public $tag = "ApplyBrokeAlms";

	public function before(){
		$this->initCacheRedis();
		return true;
	}

	public function logic() {
		
		$player =  $this->data_redis->hMGet("hu:{$this->uid}", array('broke_num', 'broke_time'));
		$broke_num = (int)$player['broke_num'];
		$broke_time = (int)$player['broke_time'];
			
		$timestamp = strtotime(date("Y-m-d"));
		$broke_info = array();
		if ($broke_time < $timestamp) {
			$broke_info['broke_num_remain'] = Game::$broke_num_max;
		} else {
			$broke_info['broke_num_remain'] = Game::$broke_num_max - $broke_num;
		}
		$broke_info['broke_num_max'] = Game::$broke_num_max;
		$broke_info['broke_give_money'] = Game::$broke_give_money;
		$broke_info['broke_money_level'] = Game::$broke_money;
		
		$keys = $this->cache_redis->lRange("lg:ids", 0, -1);
		$goodses = array();
		$rgoods = array();
		foreach ($keys as $key) {
			$goods = $this->cache_redis->hMGet("hg:{$key}", array("id", "name","type", "rmb", "money", "give_money", "give_coin", "desc"));
			$goods["type"] = (int)$goods["type"];
			if ($goods['type'] == 2) //特殊商品,破产的时候可用
			{
				$rgoods["id"] = (int)$goods["id"];
				$rgoods["rmb"] = (int)$goods["rmb"];
				$rgoods["money"] = (int)$goods["money"];
				$rgoods["give_money"] = (int)$goods["give_money"];
				$rgoods["give_coin"] = (int)$goods["give_coin"];
				break;	
			}
				
		}
				
		//$this->returnData(array("broke_info" => $broke_info,"goods_info" => $rgoods));
		$this->returnData(array("broke_info" => $broke_info));
	}

	public function after() {
		$this->deinitDataRedis();
		$this->deinitCacheRedis();
	}

}
?>
